package com.pan.test.socket.example03;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

public class MyClient03 {

    public static String PICTURE_DIR_PATH = System.getProperty("user.dir")+"\\picture\\client";

    public static void main(String[] args) throws Exception {
        InetAddress inetAddress = InetAddress.getLocalHost();
        Socket socket = new Socket(inetAddress,11451);

        File file = new File(PICTURE_DIR_PATH+"\\repair.png");
        FileInputStream fileInputStream = new FileInputStream(file);

        OutputStream outputStream = socket.getOutputStream();
        outputStream.write(fileInputStream.readAllBytes());
        socket.shutdownOutput();

        InputStream inputStream = socket.getInputStream();
        byte[] buf = new byte[1024];
        int len;
        while ((len = inputStream.read(buf))!= -1){
            System.out.println(new String(buf,0,len));
        }


        inputStream.close();
        fileInputStream.close();
        outputStream.close();
        socket.close();

    }

}

